package cn.xiaolang.function.design_pattern.publish_observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 订阅者的具体实现（增加，移除，通知观察者）
 *
 * @author fuhw/Dean
 * @date 2020-04-07
 */
public class ConcretePublish implements Publish {

    private List<Observer> list = new ArrayList<>();//观察者容器

    @Override
    public void addObserver(Observer observer) {
        list.add(observer);
    }

    @Override
    public void remove(Observer observer) {
        list.remove(observer);

    }

    @Override
    public void notifyObservers(String str) {
        for (Observer observer : list) {
            observer.update(str);
        }

    }

}
